<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>formpost.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_formpost.js.html">formpost.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line2"></a>// you may not use this file except in compliance with the License.
<a name="line3"></a>// You may obtain a copy of the License at
<a name="line4"></a>//
<a name="line5"></a>//     http://www.apache.org/licenses/LICENSE-2.0
<a name="line6"></a>//
<a name="line7"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line8"></a>// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<a name="line9"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line10"></a>// See the License for the specific language governing permissions and
<a name="line11"></a>// limitations under the License.
<a name="line12"></a>
<a name="line13"></a>// Copyright 2008 Google Inc. All Rights Reserved.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Utility for making the browser submit a hidden form, which can
<a name="line17"></a> * be used to effect a POST from JavaScript.
<a name="line18"></a> *
<a name="line19"></a> */
<a name="line20"></a>
<a name="line21"></a>goog.provide(&#39;goog.ui.FormPost&#39;);
<a name="line22"></a>
<a name="line23"></a>goog.require(&#39;goog.array&#39;);
<a name="line24"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line25"></a>goog.require(&#39;goog.string&#39;);
<a name="line26"></a>goog.require(&#39;goog.string.StringBuffer&#39;);
<a name="line27"></a>goog.require(&#39;goog.ui.Component&#39;);
<a name="line28"></a>
<a name="line29"></a>/**
<a name="line30"></a> * Creates a formpost object.
<a name="line31"></a> * @constructor
<a name="line32"></a> * @extends {goog.ui.Component}
<a name="line33"></a> * @param {goog.dom.DomHelper} opt_dom The DOM helper.
<a name="line34"></a> */
<a name="line35"></a>goog.ui.FormPost = function(opt_dom) {
<a name="line36"></a>  goog.ui.Component.call(this, opt_dom);
<a name="line37"></a>};
<a name="line38"></a>goog.inherits(goog.ui.FormPost, goog.ui.Component);
<a name="line39"></a>
<a name="line40"></a>
<a name="line41"></a>/** @inheritDoc */
<a name="line42"></a>goog.ui.FormPost.prototype.createDom = function() {
<a name="line43"></a>  this.setElementInternal(this.getDomHelper().$dom(goog.dom.TagName.FORM,
<a name="line44"></a>      {&#39;method&#39;: &#39;POST&#39;, &#39;style&#39;: &#39;display:none&#39;}));
<a name="line45"></a>};
<a name="line46"></a>
<a name="line47"></a>
<a name="line48"></a>/**
<a name="line49"></a> * Constructs a POST request and directs the browser as if a form were
<a name="line50"></a> * submitted.
<a name="line51"></a> * @param {Object} parameters Object with parameter values. Values can be
<a name="line52"></a> *     strings, numbers, or arrays of strings or numbers.
<a name="line53"></a> * @param {string} opt_url The destination URL. If not specified, uses the
<a name="line54"></a> *     current URL for window for the DOM specified in the constructor.
<a name="line55"></a> * @param {string} opt_target An optional name of a window in which to open the
<a name="line56"></a> *     URL. If not specified, uses the window for the DOM specified in the
<a name="line57"></a> *     constructor.
<a name="line58"></a> */
<a name="line59"></a>goog.ui.FormPost.prototype.post = function(parameters, opt_url, opt_target) {
<a name="line60"></a>  var form = this.getElement();
<a name="line61"></a>  if (!form) {
<a name="line62"></a>    this.render();
<a name="line63"></a>    form = this.getElement();
<a name="line64"></a>  }
<a name="line65"></a>  form.action = opt_url || &#39;&#39;;
<a name="line66"></a>  form.target = opt_target || &#39;&#39;;
<a name="line67"></a>  this.setParameters_(form, parameters);
<a name="line68"></a>  form.submit();
<a name="line69"></a>};
<a name="line70"></a>
<a name="line71"></a>
<a name="line72"></a>/**
<a name="line73"></a> * Creates hidden inputs in a form to match parameters.
<a name="line74"></a> * @param {Element} form The form element.
<a name="line75"></a> * @param {Object} parameters Object with parameter values. Values can be
<a name="line76"></a> *     strings, numbers, or arrays of strings or numbers.
<a name="line77"></a> * @private
<a name="line78"></a> */
<a name="line79"></a>goog.ui.FormPost.prototype.setParameters_ = function(form, parameters) {
<a name="line80"></a>  var name, value, sb = new goog.string.StringBuffer();
<a name="line81"></a>  for (name in parameters) {
<a name="line82"></a>    value = parameters[name];
<a name="line83"></a>    if (goog.isArrayLike(value)) {
<a name="line84"></a>      goog.array.forEach(value, goog.bind(this.appendInput_, this, sb, name));
<a name="line85"></a>    } else {
<a name="line86"></a>      this.appendInput_(sb, name, value);
<a name="line87"></a>    }
<a name="line88"></a>  }
<a name="line89"></a>  form.innerHTML = sb.toString();
<a name="line90"></a>};
<a name="line91"></a>
<a name="line92"></a>
<a name="line93"></a>/**
<a name="line94"></a> * Appends a hidden &lt;INPUT&gt; tag to a string buffer.
<a name="line95"></a> * @param {goog.string.StringBuffer} out A string buffer.
<a name="line96"></a> * @param {string} name The name of the input.
<a name="line97"></a> * @param {string} value The value of the input.
<a name="line98"></a> * @private
<a name="line99"></a> */
<a name="line100"></a>goog.ui.FormPost.prototype.appendInput_ = function(out, name, value) {
<a name="line101"></a>  out.append(
<a name="line102"></a>      &#39;&lt;input type=&quot;hidden&quot; name=&quot;&#39;,
<a name="line103"></a>      goog.string.htmlEscape(name),
<a name="line104"></a>      &#39;&quot; value=&quot;&#39;,
<a name="line105"></a>      goog.string.htmlEscape(value),
<a name="line106"></a>      &#39;&quot;&gt;&#39;);
<a name="line107"></a>};
</pre>


</body>
</html>
